package com.songshuai.webapi.baseapi.pojo;

import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class QueryRes<T> {

    /**
     * 返回码
     */
    private Integer status;

    /**
     * 返回信息描述
     */
    private String info;


    /**
     * 返回数据
     */
    private T result;


    public QueryRes() {
        status = ResultStatus.SUCCESS.getErrorCode();
        info = ResultStatus.SUCCESS.getErrorMsg();
    }

    public QueryRes(Integer status, String info) {
        this.status =status;
        this.info = info;
    }
    public QueryRes(ResultStatus resultStatus) {
        status = resultStatus.getErrorCode();
        info = resultStatus.getErrorMsg();
    }

    public QueryRes(int code, String message) {
        this.status = code;
        this.info = message;
    }

    public static <T> QueryRes setResData(T result) {
        QueryRes<T> res = new QueryRes<>();
        res.setResult(result);
        return res;
    }


    public static <T> QueryRes setResData(T result, ResultStatus resultStatus) {
        QueryRes<T> res = new QueryRes<>();
        res.setResult(result);
        res.setStatus(resultStatus.getErrorCode());
        res.setInfo(resultStatus.getErrorMsg());
        return res;
    }

    public static <T> QueryRes setResData(T result, ResultStatus resultStatus, String msg) {
        QueryRes<T> res = new QueryRes<>();
        res.setResult(result);
        res.setStatus(resultStatus.getErrorCode());
        res.setInfo(msg);
        return res;
    }

    public static <T> QueryRes setResData(T result, Integer errCode, String msg) {
        QueryRes<T> res = new QueryRes<>();
        res.setResult(result);
        res.setStatus(errCode);
        res.setInfo(msg);
        return res;
    }
}
